package com.wz.project.sap.MATERIAL.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.sap.MATERIAL.domain.ZflWmsGetMaterial;
import com.wz.project.sap.MATERIAL.service.IZflWmsGetMaterialService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 物料主数据Controller
 * 
 * @author wz
 * @date 2022-09-14
 */
@Controller
@RequestMapping("/project/MATERIAL")
public class ZflWmsGetMaterialController extends BaseController
{
    private String prefix = "project/MATERIAL";

    @Autowired
    private IZflWmsGetMaterialService zflWmsGetMaterialService;

    @RequiresPermissions("project:MATERIAL:view")
    @GetMapping()
    public String MATERIAL()
    {
        return prefix + "/MATERIAL";
    }

    /**
     * 查询物料主数据列表
     */
//    @RequiresPermissions("project:MATERIAL:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZflWmsGetMaterial zflWmsGetMaterial)
    {
        startPage();
        List<ZflWmsGetMaterial> list = zflWmsGetMaterialService.selectZflWmsGetMaterialList(zflWmsGetMaterial);
        return getDataTable(list);
    }

    /**
     * 导出物料主数据列表
     */
    @RequiresPermissions("project:MATERIAL:export")
    @Log(title = "物料主数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZflWmsGetMaterial zflWmsGetMaterial)
    {
        List<ZflWmsGetMaterial> list = zflWmsGetMaterialService.selectZflWmsGetMaterialList(zflWmsGetMaterial);
        ExcelUtil<ZflWmsGetMaterial> util = new ExcelUtil<ZflWmsGetMaterial>(ZflWmsGetMaterial.class);
        return util.exportExcel(list, "MATERIAL");
    }

    /**
     * 新增物料主数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物料主数据
     */
    @RequiresPermissions("project:MATERIAL:add")
    @Log(title = "物料主数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZflWmsGetMaterial zflWmsGetMaterial)
    {
        return toAjax(zflWmsGetMaterialService.insertZflWmsGetMaterial(zflWmsGetMaterial));
    }

    /**
     * 修改物料主数据
     */
    @GetMapping("/edit/{MATNR}")
    public String edit(@PathVariable("MATNR") String MATNR, ModelMap mmap)
    {
        ZflWmsGetMaterial zflWmsGetMaterial = zflWmsGetMaterialService.selectZflWmsGetMaterialById(MATNR);
        mmap.put("zflWmsGetMaterial", zflWmsGetMaterial);
        return prefix + "/edit";
    }

    /**
     * 修改保存物料主数据
     */
    @RequiresPermissions("project:MATERIAL:edit")
    @Log(title = "物料主数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZflWmsGetMaterial zflWmsGetMaterial)
    {
        return toAjax(zflWmsGetMaterialService.updateZflWmsGetMaterial(zflWmsGetMaterial));
    }

    /**
     * 删除物料主数据
     */
    @RequiresPermissions("project:MATERIAL:remove")
    @Log(title = "物料主数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zflWmsGetMaterialService.deleteZflWmsGetMaterialByIds(ids));
    }
}
